//
//  CZFooterView.swift
//  项目框架
//
//  Created by yang on 16/3/2.
//  Copyright © 2016年 itcast. All rights reserved.
//

import UIKit

class CZFooterView: UIView {

  //定义一个viewmodel
    var footerViewModel:CZStatusViewModel?{
    
        didSet{
            //显示数字转发
            retweetButton.setTitle(footerViewModel?.retweetString, forState: UIControlState.Normal)

        
        }
    }
    override init(frame: CGRect) {
        super.init(frame: frame)
        
        setupUI()
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    
    private func setupUI(){
        
        backgroundColor = UIColor.greenColor()
        
        addSubview(retweetButton)
        addSubview(commentsButton)
        addSubview(goodButton)
        
        let lineLeft = getLine()
        let lineRight = getLine()
        addSubview(lineLeft)
        addSubview(lineRight)
        
        // 添加约束
        
        retweetButton.snp_makeConstraints { (make) -> Void in
            
            make.left.equalTo(self.snp_left)
            make.top.equalTo(self.snp_top)
            
            make.bottom.equalTo(self.snp_bottom)
            
            //关键约束宽度
            make.width.equalTo(commentsButton.snp_width)
            
        }
        
        goodButton.snp_makeConstraints { (make) -> Void in
            make.top.equalTo(self.snp_top)
            make.right.equalTo(self.snp_right)
            make.bottom.equalTo(self.snp_bottom)
            
            //关键约束宽度
            make.width.equalTo(commentsButton.snp_width)
        }
        
        //中间的按钮
        commentsButton.snp_makeConstraints { (make) -> Void in
            make.left.equalTo(retweetButton.snp_right)
            make.top.equalTo(self.snp_top)
            make.right.equalTo(goodButton.snp_left)
            make.bottom.equalTo(self.snp_bottom)
        }
        
        
        lineLeft.snp_makeConstraints { (make) -> Void in
            make.centerX.equalTo(retweetButton.snp_right)
            make.centerY.equalTo(self.snp_centerY)
        }
        
        lineRight.snp_makeConstraints { (make) -> Void in
            make.centerX.equalTo(commentsButton.snp_right)
            make.centerY.equalTo(self.snp_centerY)
        }
    }
    
    //MARK:--懒加载
    ///转发按钮
    private lazy var retweetButton: UIButton = {
        
        let button = UIButton(type: UIButtonType.Custom)
        
        button.setImage(UIImage(named: "timeline_icon_retweet"), forState: UIControlState.Normal)
        
        button.setTitle("转发", forState: UIControlState.Normal)
        
        button.setTitleColor(UIColor(white: 0.95, alpha: 1.0), forState: UIControlState.Normal)
        
        return button
    }()
    ///评论按钮
    private lazy var commentsButton: UIButton = {
        
        let button = UIButton(type: UIButtonType.Custom)
        
        button.setImage(UIImage(named: "timeline_icon_comment"), forState: UIControlState.Normal)
        
        button.setTitle("评论", forState: UIControlState.Normal)
        
        button.setTitleColor(UIColor(white: 0.95, alpha: 1.0), forState: UIControlState.Normal)
        
        return button
    }()
    ///点赞按钮
    private lazy var goodButton: UIButton = {
        
        let button = UIButton(type: UIButtonType.Custom)
        
        button.setImage(UIImage(named: "timeline_icon_like"), forState: UIControlState.Normal)
        
        button.setTitle("赞", forState: UIControlState.Normal)
        
        button.setTitleColor(UIColor(white: 0.95, alpha: 1.0), forState: UIControlState.Normal)
        
        return button
    }()
    
    //创建一个方法,来返回一个UIImageView--线
    private func getLine() -> UIImageView{
        
        let imageView = UIImageView()
        
        imageView.image = UIImage(named: "timeline_card_bottom_line_highlighted")
        
        return imageView
    }
}


